package com.chat.chatter.ejb;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="users")
public class User implements Serializable {

   private static final long serialVersionUID = 1881413500711441951L;
   
   @Id //signifies the primary key
   @Column(name = "USER_ID", nullable = false)
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   //@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   private Long userId;

   private String username;

   private String password;

   private String name;
   
   @OneToMany ( mappedBy = "user", targetEntity=Splat.class, fetch = FetchType.EAGER, cascade =
   { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE } )
   private Set< Splat > splats = new HashSet< Splat >();

   public User() {} 
   
   public User( String name, String password, String username, Set< Splat > splats ) {

      this.name = name;

      this.password = password;

      this.username = username;
      
      this.splats = splats;

   }
   
   public long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

   public String getPassword() {
      return password;
   }

   public void setPassword( String password ) {
      this.password = password;
   }   

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
   
   //@Id
   public String getUsername() {
      return username;
   }

   public void setUsername(String username) {
      this.username = username;
   }
   
   public Set<Splat> getSplats() {
		return splats;
	}

	public void setSplats(Set<Splat> splats) {
		this.splats = splats;
	}

}
